/**
 * 
 */
package com.nari.heatshare.action;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.struts2.json.JSONUtil;
import org.apache.struts2.json.annotations.JSON;

import com.nari.baseinfo.model.IBuilding;
import com.nari.baseinfo.model.ICommunity;
import com.nari.baseinfo.model.IConcentrator;
import com.nari.baseinfo.model.IHeatRoom;
import com.nari.baseinfo.model.IProject;
import com.nari.baseinfo.service.IBuildingService;
import com.nari.baseinfo.service.ICommunityService;
import com.nari.baseinfo.service.IConcentratorService;
import com.nari.baseinfo.service.IHeatRoomService;
import com.nari.baseinfo.service.IProjectService;
import com.nari.coreframe.action.struts2.JSONActionSupport;
import com.nari.heatshare.model.IAssignMeter;
import com.nari.heatshare.model.IAssignMeterDataGather;
import com.nari.heatshare.model.IAssignMeterDataStatistics;
import com.nari.heatshare.service.IAssignMeterDataGatherService;
import com.nari.heatshare.service.IAssignMeterDataStatisticsService;
import com.nari.heatshare.service.IAssignMeterService;
import com.nari.heatshare.utils.queryvo.AssignMeterDataCustomizedQuery;
import com.nari.platform.date.CalendarUtils;
import com.nari.platform.model.PageCond;
import com.nari.platform.model.ResultWithPageCond;
import com.nari.sink.bo.PSinkInfo;
import com.nari.sink.service.ISinkBiz;
import com.opensymphony.xwork2.Action;
import com.sohoometer.web.bean.AssignDataWithInfo;
import com.sohoometer.web.bean.QuestionData;
import com.sohoometer.web.bean.QuestionDataSet;
import com.sohoometer.web.erp.utils.CollectionsUtils;
import com.sohoometer.web.excel.ExcelExportUtils;

/**
 * 
 * @author Xiaopeng
 * @date 2013-8-18
 */
public class AssignMeterDataGatherAction extends JSONActionSupport {
	private static final long serialVersionUID = -3211428951398124022L;
	private IAssignMeterDataGatherService iAssignMeterDataGatherService;
	private IProjectService iProjectService;
	private ICommunityService iCommunityService;
	private IBuildingService iBuildingService;
	private IHeatRoomService iHeatRoomService;
	private IConcentratorService iConcentratorService;
	private IAssignMeterService iAssignMeterService;
	private ISinkBiz iSinkBiz;
	private IAssignMeterDataStatisticsService iAssignMeterDataStatisticsService;
	private String concentratorNo;
	private Date startDate;
	private Date endDate;
	//分页查询
	private int pageIndex = 1; //默认查询第一页列表
	private PageCond pageCond;
	private int pageSize;
	private boolean nopage;
	private ResultWithPageCond<IAssignMeterDataGather> meterDataPage;
	
	private Map<String, String> pageConcentratorMap;
	//分配表数据管理
	private String meterDataUID;
	private IAssignMeterDataGather meterData;
	private String projectUID;
	private String communityUID;
	private String buildingUID;
	private String heatRoomUID;
	private List<IProject> projectList;
	private List<ICommunity> communityList;
	private List<IBuilding> buildingList;
	private List<IHeatRoom> heatRoomList;
	private List<IConcentrator> concentratorList;
	private List<IAssignMeter> assignMeterList;
	private String concentratorUID;
	private String assignMeterUID;
	private IAssignMeter assignMeter;
	private String dataUploadType; //区分TXT上传、GPRS批量上传
	//上传批次的分配表数据查询
	private Date recordTime;
	private Date readTime;//读取时间
	private String meterDataStatisUID;
	private IAssignMeterDataStatistics meterDataStatis;
	private double uploadPercent;
	private String seriousNum;
	private String illegalIDList; //校验失败的分配表数据ID
	//分配表数据定制查询
	private Date recordTimeStart;
	private Date recordTimeEnd;
	private Map<String, String> pageProjectMap;
	private Map<String, String> pageCommunityMap;
	private Map<String, String> pageBuildingMap;
	private Map<String, String> pageHouseNoMap;
	private ResultWithPageCond<AssignMeterDataCustomizedQuery> customizedQueryPage;
	private AssignMeterDataCustomizedQuery amdCustomizedQuery;
	private List<IAssignMeterDataGather> assignMeterDataList;
	private List<AssignDataWithInfo> dataWithInfos;
	//TXT上传分配表数据查询
	private String dataFileUID;
	//查询分配表详细资料
	private IProject project;
	private ICommunity community;
	private IBuilding building;
	private IHeatRoom heatRoom;
	private IConcentrator concentrator;
	private PSinkInfo heatSinker;
	//上传批次数据与档案信息匹配校验
	private String batch2BaseinfoMatch;
	private List<IAssignMeterDataGather> meterDataList;
	private Integer dataType;
	private ArrayList<QuestionData> questionDatas;
	private ArrayList<String> questionDataIDs;
	private String no;
	private List<IAssignMeterDataGather> seriousNumList;
	
	/**
	 * 查询分配表数据批次上传的详细资料
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-10-25
	 */
	public String queryMeterDataBatchDetail() throws Exception {
		//分配表数据的批次上传统计信息
		this.meterDataStatis = iAssignMeterDataStatisticsService.queryEntityById(meterDataStatisUID);
		//所属楼栋
		this.concentrator = iConcentratorService.queryByConcentratorNo(meterDataStatis.getConcentratorNo());
		if(concentrator != null) {
			//所属项目
			this.project = iProjectService.queryEntityById(concentrator.getProjectID());
			//所属小区
			this.community = iCommunityService.queryEntityById(concentrator.getCommunityID());
			//所属楼栋
			if(concentrator.getBuildingID()!=null && !"".equals(concentrator.getBuildingID())) {
				this.building = iBuildingService.queryEntityById(concentrator.getBuildingID());
			}
		}
		//批次数据与档案信息匹配校验
		if(meterDataStatis != null) {
			List<String> matchResultList = iAssignMeterDataGatherService.queryLackBaseinfoSeriousNum(meterDataStatis.getConcentratorNo(), 
					meterDataStatis.getRecordTime(), null);
			if(matchResultList!=null && matchResultList.size()>0) {
				StringBuffer matchResult = new StringBuffer("");
				for(int index=0; index<matchResultList.size(); index++) {
					matchResult.append(matchResultList.get(index));
					if(index < matchResultList.size()-1) {
						matchResult.append(",");
					}
					if((index+1)%3 == 0) {
						matchResult.append("\n");
					}
				}
				this.batch2BaseinfoMatch = matchResult.toString();
			}
		}
		return "uploadBatchDetail";
	}
	
	/**
	 * 通过集中器上传批次任务(集中器号、抄表日期)分页查询分配表数据
	 * 定点查询-抄表数据
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-10-25
	 */
	public String queryMeterDataPageByUploadBatch() throws Exception {
		//分页信息
		this.pageCond = new PageCond();
		int start = (this.pageIndex - 1) * this.pageCond.getLimit();
		this.pageCond.setStart(start);
		//分页结果
		this.meterDataPage = iAssignMeterDataGatherService.queryMeterDataPageByUploadBatch(concentratorNo, 
				recordTime, seriousNum, startDate, endDate, pageCond);
		//计算结果集的页数
		this.pageSize = new BigDecimal(this.meterDataPage.getPageCond().getTotal())
				.divide(new BigDecimal(this.meterDataPage.getPageCond().getLimit()), RoundingMode.UP).intValue();
		if(pageSize == 0) pageSize = 1;
		//校验分配表数据的合规性，并记录不合规的分配表数据ID
		this.illegalIDList = iAssignMeterDataGatherService.checkMeterDataLegality(meterDataPage.getList());
		//查询与批次上传时间不匹配的分配表数据ID
		String nonMatchReadTimeUIDList = iAssignMeterDataGatherService.queryNonMatchReadTime4Batch(concentratorNo, recordTime);
		illegalIDList += nonMatchReadTimeUIDList;
		return "uploadBatchPage";
	}
	
	/**
	 * 通过集中器上传批次任务(集中器号、抄表日期)分页查询分配表数据
	 * 定点查询-抄表数据
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-10-25
	 */
	public String queryMeterDataPageByUploadBatchByColor() throws Exception {
		queryMeterDataPageByUploadBatch();
		queryQuestionData();
		this.questionDataIDs=iAssignMeterDataGatherService.getQuestionDataIDs(questionDatas);
		return "uploadBatchPage";
	}
	
	
	/**
	 * 分页查询分配表数据
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-9-1
	 */
	public String queryMeterDataPage() throws Exception {
		//分页信息
		this.pageCond = new PageCond();
		int start = (this.pageIndex - 1) * this.pageCond.getLimit();
		this.pageCond.setStart(start);
		//分页结果
		this.meterDataPage = this.iAssignMeterDataGatherService.queryMeterDataPage(concentratorNo, startDate, endDate, pageCond);
		//计算结果集的页数
		this.pageSize = new BigDecimal(this.meterDataPage.getPageCond().getTotal())
				.divide(new BigDecimal(this.meterDataPage.getPageCond().getLimit()), RoundingMode.UP).intValue();
		if(pageSize == 0) pageSize = 1;
		//校验分配表数据的合规性，并记录不合规的分配表数据ID
		this.illegalIDList = iAssignMeterDataGatherService.checkMeterDataLegality(meterDataPage.getList());
		return "meterDataPage";
	}
	
	/**
	 * 分页查询分配表数据定制查询列表
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-11-29
	 */
	public String queryCustomizedAmDataPage() throws Exception {
		//所属项目列表
		this.projectList = this.iProjectService.queryAllProjectInOrder();
		if(this.projectList == null) {
			this.projectList = new ArrayList<IProject>();
		}
		//所属小区列表
		if(this.projectUID!=null && !"".equals(projectUID)) {
			this.communityList = this.iCommunityService.queryCommunitysByBelongings(null, null, null, projectUID);
		} else {
			this.communityList = new ArrayList<ICommunity>();
		}
		//所属楼栋列表
		this.buildingList = this.iBuildingService.queryBuildingByBelongings(projectUID, communityUID);
		//所属热用户
		this.heatRoomList = this.iHeatRoomService.queryHeatRoomsByBelongs(projectUID, communityUID, null, buildingUID);
		//分页查询
		this.pageCond = new PageCond();
		if(nopage) {
			pageCond.setLimit(1000);
		}
		int start = (this.pageIndex - 1) * this.pageCond.getLimit();
		this.pageCond.setStart(start);
		//设置查询的抄表日期，遵循就近一致原则
		if(this.recordTimeStart==null && this.recordTimeEnd==null) {
			this.recordTimeStart = this.recordTimeEnd = new Date();
		}
		if(this.recordTimeStart!=null && this.recordTimeEnd==null) {
			this.recordTimeEnd = this.recordTimeStart;
		}
		if(this.recordTimeStart==null && this.recordTimeEnd!=null) {
			this.recordTimeStart = this.recordTimeEnd;
		}
		this.customizedQueryPage = iAssignMeterDataGatherService.queryCustomizedQueryPage(projectUID, 
				communityUID, buildingUID, recordTimeStart, recordTimeEnd, pageCond);
		//计算结果集的页数
		this.pageSize = new BigDecimal(this.customizedQueryPage.getPageCond().getTotal())
				.divide(new BigDecimal(this.customizedQueryPage.getPageCond().getLimit()), RoundingMode.UP).intValue();
		if(pageSize == 0) pageSize = 1;
		// 项目映射表
		this.pageProjectMap = new HashMap<String, String>();
		for (IProject project : this.projectList) {
			this.pageProjectMap.put(project.getId(), project.getProjectName());
		}
		// 小区映射表
		this.pageCommunityMap = iAssignMeterDataGatherService.queryReferCommunitysByCustomizedList(customizedQueryPage.getList());
		//楼栋映射表
		this.pageBuildingMap = iAssignMeterDataGatherService.queryReferBuildingsByCustomizedList(customizedQueryPage.getList());
		return "customizedPage";
	}
	
	/**
	 * 查询定制查询详细信息(依楼栋分类)
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-12-10
	 */
	public String queryCustomizedAmDataDetail() throws Exception {
		//楼栋数据定制的详细资料
		this.amdCustomizedQuery = iAssignMeterDataGatherService.queryBuildingCustomizedQuery(buildingUID, recordTime);
		//所属楼栋
		if(this.buildingUID!=null && !"".equals(buildingUID)) {
			this.building = iBuildingService.queryEntityById(buildingUID);
		}
		if(building != null) {
			//所属小区
			this.community = iCommunityService.queryEntityById(building.getCommunityID());
			//所属项目
			this.project = iProjectService.queryEntityById(building.getProjectID());
		}
		return "buildingAmDataDetail";
	}
	
	/**
	 * 查询楼栋所属分配表的抄收数据
	 * 定制查询-分配表数据
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-12-10
	 */
	public String queryBuildingAmDataList() throws Exception {
		//分页查询
		this.pageCond = new PageCond();
		int start = (this.pageIndex - 1) * this.pageCond.getLimit();
		this.pageCond.setStart(start);
		if (nopage) {
			pageCond.setLimit(1000);
		}
		this.meterDataPage = iAssignMeterDataGatherService.queryCustomizedAmDataList(buildingUID, recordTime, pageCond);
		//计算结果集的页数
		this.pageSize = new BigDecimal(this.meterDataPage.getPageCond().getTotal())
				.divide(new BigDecimal(this.meterDataPage.getPageCond().getLimit()), RoundingMode.UP).intValue();
		if(pageSize == 0) pageSize = 1;
		//校验分配表数据的合规性，并记录不合规的分配表数据ID
		this.illegalIDList = iAssignMeterDataGatherService.checkMeterDataLegality(meterDataPage.getList());
		return "buildingAmDataList";
	}
	
	/**
	 * 分配表数据管理
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-9-1
	 */
	public String queryMeterDataForManage() throws Exception {
		if(this.meterDataUID!=null && !"".equals(meterDataUID)) {
			this.meterData = this.iAssignMeterDataGatherService.queryEntityById(meterDataUID);
		}
		//分配表数据上传方式dataUploadType: txtUpload、batchUpload
		return "meterDataManage";
	}
	
	/**
	 * 新增或修改分配表数据
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-9-2
	 */
	public String saveOrUpdateMeterData() throws Exception {
		//人工新增的数据设置为平滑数据
		if(meterData.getId()==null || "".equals(meterData.getId().trim())) {
			meterData.setDataType(0);
		}
		//所有类型分配表数据的新增、修改操作
		this.rmsg = this.iAssignMeterDataGatherService.saveOrUpdateMeterData(meterData);
		this.writeJsonStrToResponse(JSONUtil.serialize(this.rmsg));
		return Action.SUCCESS;
	}

	/**
	 * 根据唯一标识删除分配表数据
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-9-2
	 */
	public String deleteMeterDataByUID() throws Exception {
		this.rmsg = iAssignMeterDataGatherService.deleteMeterDataByUID(meterDataUID);
		this.writeJsonStrToResponse(JSONUtil.serialize(rmsg));
		return Action.SUCCESS;
	}
	
	/**
	 * TXT上传分配表数据查询
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-10-29
	 */
	public String queryMeterDataPageByFileID() throws Exception {
		//分页信息
		this.pageCond = new PageCond();
		int start = (this.pageIndex - 1) * this.pageCond.getLimit();
		this.pageCond.setStart(start);
		//分页结果
		this.meterDataPage = iAssignMeterDataGatherService.queryMeterDataPageByFileID(dataFileUID, 
				seriousNum, pageCond);
		//计算结果集的页数
		this.pageSize = new BigDecimal(this.meterDataPage.getPageCond().getTotal())
				.divide(new BigDecimal(this.meterDataPage.getPageCond().getLimit()), RoundingMode.UP).intValue();
		if(pageSize == 0) pageSize = 1;
		//校验分配表数据的合规性，并记录不合规的分配表数据ID
		this.illegalIDList = iAssignMeterDataGatherService.checkMeterDataLegality(meterDataPage.getList());
		return "txtUploadPage";
	}
	
	/**
	 * 查询分配表数据详细资料
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-12-8
	 */
	public String queryMeterDataDetail() throws Exception {
		if(meterDataUID!=null && !"".equals(meterDataUID)) {
			//分配表数据
			this.meterData = iAssignMeterDataGatherService.queryEntityById(meterDataUID);
			//分配表
			this.assignMeter = iAssignMeterService.queryMeterBySeriousNum(meterData.getSeriousNum());
			if(assignMeter != null) {
				//所属项目
				this.project = this.iProjectService.queryEntityById(assignMeter.getProjectID());
				//所属小区
				this.community = this.iCommunityService.queryEntityById(assignMeter.getCommunityID());
				//所属楼栋
				this.building = this.iBuildingService.queryEntityById(assignMeter.getBuildingID());
				//所属热用户
				this.heatRoom = this.iHeatRoomService.queryEntityById(assignMeter.getRoomId());
				//集中器
				this.concentrator = this.iConcentratorService.queryEntityById(assignMeter.getConcentratorID());
				//挂接散热器
				this.heatSinker = this.iSinkBiz.queryEntityById(assignMeter.getHeatSinkID());
			}
		}
		return "meterDataDetail";
	}
	
	/**
	 * 查询校验不合规的分配表数据列表
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-4-2
	 */
	public String queryNonRationalMeterDataList() throws Exception {
		this.meterDataList = iAssignMeterDataGatherService.queryNonRationalDataByBatch(concentratorNo, recordTime, null);
		return "nonRationalList";
	}
	
	/**
	 * 异常数据报警
	 * 1.温度异常      前板温度比背板温度大于3度或者任何温度大于60度   表格背景颜色 
	 * 2.热阻塞          前后板温度均大于35度 且温差小于2度	     表格背景颜色
	 * 3.电池报警   			表格背景颜色
	 * 4.通讯故障报警 	表格背景颜色
	 * */
	public String queryQuestionData() throws Exception{
				questionDatas = iAssignMeterDataGatherService.getQuestionDatas(concentratorNo, recordTime);
		return "exceptionDataList";
	}
	/**
	 * 增加电池异常
	 * */
	public String addBatteryException() {
		if(StringUtils.isNoneBlank(no)) {
			QuestionDataSet.addBatteryException(no);
		}
		return null;
	}
	/**
	 * 移除电池异常
	 * */
	public String removeBatteryException() {
		if(StringUtils.isNoneBlank(no)) {
			QuestionDataSet.removeBatteryException(no);
		}
		return null;
	}
	/**
	 * 增加通讯异常
	 * */
	public String addCommException() {
		if(StringUtils.isNoneBlank(no)) {
			QuestionDataSet.addCommException(no);
		}
		return null;
	}
	/**
	 * 移除通讯异常
	 * */
	public String removeCommException() {
		if(StringUtils.isNoneBlank(no)) {
			QuestionDataSet.removeCommException(no);
		}
		return null;
	}
	
	/**
	 * 下载TXT格式分配表数据调试文件
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-4-3
	 */
	public String downloadDebugTxt() throws Exception {
		//查询分配表数据批次统计信息
		this.meterDataStatis = iAssignMeterDataStatisticsService.queryEntityById(meterDataStatisUID);
		if(meterDataStatis != null) {
			this.meterDataList = iAssignMeterDataGatherService.queryMeterDatasByBatch(meterDataStatis.getConcentratorNo(), 
					meterDataStatis.getRecordTime(), dataType);
			//设置下载文件时的显示名称
			String recordTime = CalendarUtils.parseDateToString(meterDataStatis.getRecordTime());
			this.setOutputFileName(meterDataStatis.getConcentratorNo()+"_"+recordTime+"_抄表文件.txt");
		}
		//生成TXT文件
		this.rmsg = iAssignMeterDataGatherService.generateTxtDebugFile(meterDataList);
		//设置下载文件输出流
		this.setTargetFile(new FileInputStream(new File(this.rmsg.getMsg())));
		return "downloadFile";
	}
	
		/**
	 * 导出分配表查询数据
	 * */
	public String exportAssignMeterCustomerQueryData() throws Exception{
	nopage = true;
	queryCustomizedAmDataPage();
	IProject project = CollectionsUtils.getElement(projectList, "id", projectUID);
	ICommunity community = CollectionsUtils.getElement(communityList, "id", communityUID);
	 HSSFWorkbook heatMeasureCommunityWorkbook = new ExcelExportUtils().getAssignCommunityUploadData(project, community, recordTimeStart, recordTimeEnd, customizedQueryPage.getList(), pageProjectMap, pageCommunityMap, pageBuildingMap);
	 ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
	 heatMeasureCommunityWorkbook.write(byteStream);
	 ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteStream.toByteArray());
	 setTargetFile(byteArrayInputStream);
	 String name = "分配表小区整体上传率定制查询下载.xls";
//	 String newName = new String(name.getBytes("utf-8"),"iso-8859-1");
	 setOutputFileName(URLEncoder.encode(name, "utf-8"));
	 IOUtils.closeQuietly(byteStream);
	 return "downloadFile";
	}
	
	/**
	 * 导出 分配表数据定制查询资料 详细
	 * */
	public String exportAssignMeterBuildingDetailData() throws Exception{
		nopage=true;
	queryCustomizedAmDataDetail();
	queryBuildingAmDataList();
//	 HSSFWorkbook heatMeasureCommunityWorkbook = new ExcelExportUtils().getBuildingAssignMeterInfoWorkBook(project, community, building, amdCustomizedQuery, meterDataPage.getList());
	pageCond.setLimit(1000000000);
	ResultWithPageCond<AssignDataWithInfo> assignDataWithInfo = iAssignMeterDataGatherService.queryAssignDataWithInfo(buildingUID, recordTime, pageCond);
	 HSSFWorkbook heatMeasureCommunityWorkbook = new ExcelExportUtils().getBuildingAssignMeterInfoWorkBook(project, community, building, assignDataWithInfo.getList(), amdCustomizedQuery);
	 ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
	 heatMeasureCommunityWorkbook.write(byteStream);
	 ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteStream.toByteArray());
	 setTargetFile(byteArrayInputStream);
	 String name = "楼栋分配表详细信息定制下载.xls";
//	 String newName = new String(name.getBytes("utf-8"),"iso-8859-1");
	 setOutputFileName(URLEncoder.encode(name, "utf-8"));
	 IOUtils.closeQuietly(byteStream);
	 return "downloadFile";
	}

	
	/**
	 * 定制查询中楼栋分配表数据,同时将数据以门牌号进行排列
	 * @throws Exception */
	public String queryAssignDataWithInfo() throws Exception {
		//分页信息
		this.pageCond = new PageCond();
		int start = (this.pageIndex - 1) * this.pageCond.getLimit();
		this.pageCond.setStart(start);
		ResultWithPageCond<AssignDataWithInfo> queryAssignDataWithInfo = iAssignMeterDataGatherService.queryAssignDataWithInfo(buildingUID, recordTime, pageCond);
	this.dataWithInfos=queryAssignDataWithInfo.getList();
		//计算结果集的页数
		this.pageSize = new BigDecimal(queryAssignDataWithInfo.getPageCond().getTotal())
				.divide(new BigDecimal(queryAssignDataWithInfo.getPageCond().getLimit()), RoundingMode.UP).intValue();
		if(pageSize == 0) pageSize = 1;
		return "buildingAmDataAndInfoList";
	}
	
public String pickOutData() throws Exception{
		this.assignMeterDataList = iAssignMeterDataGatherService.getUnUploadRegisteData(concentratorNo, recordTime,readTime);
		return "pickOut";
	}
	/**
	 * @return the iAssignMeterDataGatherService
	 */
	@JSON(serialize=false)
	public IAssignMeterDataGatherService getiAssignMeterDataGatherService() {
		return iAssignMeterDataGatherService;
	}
	
	/**
	 * @param iAssignMeterDataGatherService the iAssignMeterDataGatherService to set
	 */
	public void setiAssignMeterDataGatherService(
			IAssignMeterDataGatherService iAssignMeterDataGatherService) {
		this.iAssignMeterDataGatherService = iAssignMeterDataGatherService;
	}

	/**
	 * @return the iProjectService
	 */
	@JSON(serialize=false)
	public IProjectService getiProjectService() {
		return iProjectService;
	}

	/**
	 * @param iProjectService the iProjectService to set
	 */
	public void setiProjectService(IProjectService iProjectService) {
		this.iProjectService = iProjectService;
	}

	/**
	 * @return the iCommunityService
	 */
	@JSON(serialize=false)
	public ICommunityService getiCommunityService() {
		return iCommunityService;
	}

	/**
	 * @param iCommunityService the iCommunityService to set
	 */
	public void setiCommunityService(ICommunityService iCommunityService) {
		this.iCommunityService = iCommunityService;
	}

	/**
	 * @return the iBuildingService
	 */
	@JSON(serialize=false)
	public IBuildingService getiBuildingService() {
		return iBuildingService;
	}

	/**
	 * @param iBuildingService the iBuildingService to set
	 */
	public void setiBuildingService(IBuildingService iBuildingService) {
		this.iBuildingService = iBuildingService;
	}

	/**
	 * @return the iHeatRoomService
	 */
	@JSON(serialize=false)
	public IHeatRoomService getiHeatRoomService() {
		return iHeatRoomService;
	}

	/**
	 * @param iHeatRoomService the iHeatRoomService to set
	 */
	public void setiHeatRoomService(IHeatRoomService iHeatRoomService) {
		this.iHeatRoomService = iHeatRoomService;
	}

	/**
	 * @return the iConcentratorService
	 */
	@JSON(serialize=false)
	public IConcentratorService getiConcentratorService() {
		return iConcentratorService;
	}

	/**
	 * @param iConcentratorService the iConcentratorService to set
	 */
	public void setiConcentratorService(IConcentratorService iConcentratorService) {
		this.iConcentratorService = iConcentratorService;
	}

	/**
	 * @return the iAssignMeterService
	 */
	@JSON(serialize=false)
	public IAssignMeterService getiAssignMeterService() {
		return iAssignMeterService;
	}

	/**
	 * @param iAssignMeterService the iAssignMeterService to set
	 */
	public void setiAssignMeterService(IAssignMeterService iAssignMeterService) {
		this.iAssignMeterService = iAssignMeterService;
	}

	/**
	 * @return the iSinkBiz
	 */
	@JSON(serialize=false)
	public ISinkBiz getiSinkBiz() {
		return iSinkBiz;
	}

	/**
	 * @param iSinkBiz the iSinkBiz to set
	 */
	public void setiSinkBiz(ISinkBiz iSinkBiz) {
		this.iSinkBiz = iSinkBiz;
	}

	/**
	 * @return the iAssignMeterDataStatisticsService
	 */
	@JSON(serialize=false)
	public IAssignMeterDataStatisticsService getiAssignMeterDataStatisticsService() {
		return iAssignMeterDataStatisticsService;
	}

	/**
	 * @param iAssignMeterDataStatisticsService the iAssignMeterDataStatisticsService to set
	 */
	public void setiAssignMeterDataStatisticsService(
			IAssignMeterDataStatisticsService iAssignMeterDataStatisticsService) {
		this.iAssignMeterDataStatisticsService = iAssignMeterDataStatisticsService;
	}

	/**
	 * @return the concentratorNo
	 */
	public String getConcentratorNo() {
		return concentratorNo;
	}

	/**
	 * @param concentratorNo the concentratorNo to set
	 */
	public void setConcentratorNo(String concentratorNo) {
		this.concentratorNo = concentratorNo;
	}

	/**
	 * @return the startDate
	 */
	public Date getStartDate() {
		return startDate;
	}

	/**
	 * @param startDate the startDate to set
	 */
	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	/**
	 * @return the endDate
	 */
	public Date getEndDate() {
		return endDate;
	}

	/**
	 * @param endDate the endDate to set
	 */
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	/**
	 * @return the pageIndex
	 */
	public int getPageIndex() {
		return pageIndex;
	}

	/**
	 * @param pageIndex the pageIndex to set
	 */
	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}

	/**
	 * @return the pageCond
	 */
	public PageCond getPageCond() {
		return pageCond;
	}

	/**
	 * @param pageCond the pageCond to set
	 */
	public void setPageCond(PageCond pageCond) {
		this.pageCond = pageCond;
	}

	/**
	 * @return the pageSize
	 */
	public int getPageSize() {
		return pageSize;
	}

	/**
	 * @param pageSize the pageSize to set
	 */
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	/**
	 * @return the meterDataPage
	 */
	public ResultWithPageCond<IAssignMeterDataGather> getMeterDataPage() {
		return meterDataPage;
	}

	/**
	 * @param meterDataPage the meterDataPage to set
	 */
	public void setMeterDataPage(
			ResultWithPageCond<IAssignMeterDataGather> meterDataPage) {
		this.meterDataPage = meterDataPage;
	}

	/**
	 * @return the pageConcentratorMap
	 */
	public Map<String, String> getPageConcentratorMap() {
		return pageConcentratorMap;
	}

	/**
	 * @param pageConcentratorMap the pageConcentratorMap to set
	 */
	public void setPageConcentratorMap(Map<String, String> pageConcentratorMap) {
		this.pageConcentratorMap = pageConcentratorMap;
	}

	/**
	 * @return the meterDataUID
	 */
	public String getMeterDataUID() {
		return meterDataUID;
	}

	/**
	 * @param meterDataUID the meterDataUID to set
	 */
	public void setMeterDataUID(String meterDataUID) {
		this.meterDataUID = meterDataUID;
	}

	/**
	 * @return the meterData
	 */
	public IAssignMeterDataGather getMeterData() {
		return meterData;
	}

	/**
	 * @param meterData the meterData to set
	 */
	public void setMeterData(IAssignMeterDataGather meterData) {
		this.meterData = meterData;
	}

	/**
	 * @return the projectUID
	 */
	public String getProjectUID() {
		return projectUID;
	}

	/**
	 * @param projectUID the projectUID to set
	 */
	public void setProjectUID(String projectUID) {
		this.projectUID = projectUID;
	}

	/**
	 * @return the communityUID
	 */
	public String getCommunityUID() {
		return communityUID;
	}

	/**
	 * @param communityUID the communityUID to set
	 */
	public void setCommunityUID(String communityUID) {
		this.communityUID = communityUID;
	}

	/**
	 * @return the buildingUID
	 */
	public String getBuildingUID() {
		return buildingUID;
	}

	/**
	 * @param buildingUID the buildingUID to set
	 */
	public void setBuildingUID(String buildingUID) {
		this.buildingUID = buildingUID;
	}

	/**
	 * @return the heatRoomUID
	 */
	public String getHeatRoomUID() {
		return heatRoomUID;
	}

	/**
	 * @param heatRoomUID the heatRoomUID to set
	 */
	public void setHeatRoomUID(String heatRoomUID) {
		this.heatRoomUID = heatRoomUID;
	}

	/**
	 * @return the projectList
	 */
	public List<IProject> getProjectList() {
		return projectList;
	}

	/**
	 * @param projectList the projectList to set
	 */
	public void setProjectList(List<IProject> projectList) {
		this.projectList = projectList;
	}

	/**
	 * @return the communityList
	 */
	public List<ICommunity> getCommunityList() {
		return communityList;
	}

	/**
	 * @param communityList the communityList to set
	 */
	public void setCommunityList(List<ICommunity> communityList) {
		this.communityList = communityList;
	}

	/**
	 * @return the buildingList
	 */
	public List<IBuilding> getBuildingList() {
		return buildingList;
	}

	/**
	 * @param buildingList the buildingList to set
	 */
	public void setBuildingList(List<IBuilding> buildingList) {
		this.buildingList = buildingList;
	}

	/**
	 * @return the heatRoomList
	 */
	public List<IHeatRoom> getHeatRoomList() {
		return heatRoomList;
	}

	/**
	 * @param heatRoomList the heatRoomList to set
	 */
	public void setHeatRoomList(List<IHeatRoom> heatRoomList) {
		this.heatRoomList = heatRoomList;
	}

	/**
	 * @return the concentratorList
	 */
	public List<IConcentrator> getConcentratorList() {
		return concentratorList;
	}

	/**
	 * @param concentratorList the concentratorList to set
	 */
	public void setConcentratorList(List<IConcentrator> concentratorList) {
		this.concentratorList = concentratorList;
	}

	/**
	 * @return the assignMeterList
	 */
	public List<IAssignMeter> getAssignMeterList() {
		return assignMeterList;
	}

	/**
	 * @param assignMeterList the assignMeterList to set
	 */
	public void setAssignMeterList(List<IAssignMeter> assignMeterList) {
		this.assignMeterList = assignMeterList;
	}

	/**
	 * @return the concentratorUID
	 */
	public String getConcentratorUID() {
		return concentratorUID;
	}

	/**
	 * @param concentratorUID the concentratorUID to set
	 */
	public void setConcentratorUID(String concentratorUID) {
		this.concentratorUID = concentratorUID;
	}

	/**
	 * @return the assignMeterUID
	 */
	public String getAssignMeterUID() {
		return assignMeterUID;
	}

	/**
	 * @param assignMeterUID the assignMeterUID to set
	 */
	public void setAssignMeterUID(String assignMeterUID) {
		this.assignMeterUID = assignMeterUID;
	}

	/**
	 * @return the assignMeter
	 */
	public IAssignMeter getAssignMeter() {
		return assignMeter;
	}

	/**
	 * @param assignMeter the assignMeter to set
	 */
	public void setAssignMeter(IAssignMeter assignMeter) {
		this.assignMeter = assignMeter;
	}

	/**
	 * @return the dataUploadType
	 */
	public String getDataUploadType() {
		return dataUploadType;
	}

	/**
	 * @param dataUploadType the dataUploadType to set
	 */
	public void setDataUploadType(String dataUploadType) {
		this.dataUploadType = dataUploadType;
	}

	/**
	 * @return the recordTime
	 */
	public Date getRecordTime() {
		return recordTime;
	}

	/**
	 * @param recordTime the recordTime to set
	 */
	public void setRecordTime(Date recordTime) {
		this.recordTime = recordTime;
	}

	/**
	 * @return the meterDataStatisUID
	 */
	public String getMeterDataStatisUID() {
		return meterDataStatisUID;
	}

	/**
	 * @param meterDataStatisUID the meterDataStatisUID to set
	 */
	public void setMeterDataStatisUID(String meterDataStatisUID) {
		this.meterDataStatisUID = meterDataStatisUID;
	}

	/**
	 * @return the meterDataStatis
	 */
	public IAssignMeterDataStatistics getMeterDataStatis() {
		return meterDataStatis;
	}

	/**
	 * @param meterDataStatis the meterDataStatis to set
	 */
	public void setMeterDataStatis(IAssignMeterDataStatistics meterDataStatis) {
		this.meterDataStatis = meterDataStatis;
	}

	/**
	 * @return the uploadPercent
	 */
	public double getUploadPercent() {
		return uploadPercent;
	}

	/**
	 * @param uploadPercent the uploadPercent to set
	 */
	public void setUploadPercent(double uploadPercent) {
		this.uploadPercent = uploadPercent;
	}

	/**
	 * @return the seriousNum
	 */
	public String getSeriousNum() {
		return seriousNum;
	}

	/**
	 * @param seriousNum the seriousNum to set
	 */
	public void setSeriousNum(String seriousNum) {
		this.seriousNum = seriousNum;
	}

	/**
	 * @return the illegalIDList
	 */
	public String getIllegalIDList() {
		return illegalIDList;
	}

	/**
	 * @param illegalIDList the illegalIDList to set
	 */
	public void setIllegalIDList(String illegalIDList) {
		this.illegalIDList = illegalIDList;
	}

	/**
	 * @return the recordTimeStart
	 */
	public Date getRecordTimeStart() {
		return recordTimeStart;
	}

	/**
	 * @param recordTimeStart the recordTimeStart to set
	 */
	public void setRecordTimeStart(Date recordTimeStart) {
		this.recordTimeStart = recordTimeStart;
	}

	/**
	 * @return the recordTimeEnd
	 */
	public Date getRecordTimeEnd() {
		return recordTimeEnd;
	}

	/**
	 * @param recordTimeEnd the recordTimeEnd to set
	 */
	public void setRecordTimeEnd(Date recordTimeEnd) {
		this.recordTimeEnd = recordTimeEnd;
	}

	/**
	 * @return the pageProjectMap
	 */
	public Map<String, String> getPageProjectMap() {
		return pageProjectMap;
	}

	/**
	 * @param pageProjectMap the pageProjectMap to set
	 */
	public void setPageProjectMap(Map<String, String> pageProjectMap) {
		this.pageProjectMap = pageProjectMap;
	}

	/**
	 * @return the pageCommunityMap
	 */
	public Map<String, String> getPageCommunityMap() {
		return pageCommunityMap;
	}

	/**
	 * @param pageCommunityMap the pageCommunityMap to set
	 */
	public void setPageCommunityMap(Map<String, String> pageCommunityMap) {
		this.pageCommunityMap = pageCommunityMap;
	}

	/**
	 * @return the pageBuildingMap
	 */
	public Map<String, String> getPageBuildingMap() {
		return pageBuildingMap;
	}

	/**
	 * @param pageBuildingMap the pageBuildingMap to set
	 */
	public void setPageBuildingMap(Map<String, String> pageBuildingMap) {
		this.pageBuildingMap = pageBuildingMap;
	}

	/**
	 * @return the pageHouseNoMap
	 */
	public Map<String, String> getPageHouseNoMap() {
		return pageHouseNoMap;
	}

	/**
	 * @param pageHouseNoMap the pageHouseNoMap to set
	 */
	public void setPageHouseNoMap(Map<String, String> pageHouseNoMap) {
		this.pageHouseNoMap = pageHouseNoMap;
	}

	/**
	 * @return the customizedQueryPage
	 */
	public ResultWithPageCond<AssignMeterDataCustomizedQuery> getCustomizedQueryPage() {
		return customizedQueryPage;
	}

	/**
	 * @param customizedQueryPage the customizedQueryPage to set
	 */
	public void setCustomizedQueryPage(
			ResultWithPageCond<AssignMeterDataCustomizedQuery> customizedQueryPage) {
		this.customizedQueryPage = customizedQueryPage;
	}

	/**
	 * @return the amdCustomizedQuery
	 */
	public AssignMeterDataCustomizedQuery getAmdCustomizedQuery() {
		return amdCustomizedQuery;
	}

	/**
	 * @param amdCustomizedQuery the amdCustomizedQuery to set
	 */
	public void setAmdCustomizedQuery(
			AssignMeterDataCustomizedQuery amdCustomizedQuery) {
		this.amdCustomizedQuery = amdCustomizedQuery;
	}

	/**
	 * @return the assignMeterDataList
	 */
	public List<IAssignMeterDataGather> getAssignMeterDataList() {
		return assignMeterDataList;
	}

	/**
	 * @param assignMeterDataList the assignMeterDataList to set
	 */
	public void setAssignMeterDataList(
			List<IAssignMeterDataGather> assignMeterDataList) {
		this.assignMeterDataList = assignMeterDataList;
	}

	/**
	 * @return the dataFileUID
	 */
	public String getDataFileUID() {
		return dataFileUID;
	}

	/**
	 * @param dataFileUID the dataFileUID to set
	 */
	public void setDataFileUID(String dataFileUID) {
		this.dataFileUID = dataFileUID;
	}

	/**
	 * @return the project
	 */
	public IProject getProject() {
		return project;
	}

	/**
	 * @param project the project to set
	 */
	public void setProject(IProject project) {
		this.project = project;
	}

	/**
	 * @return the community
	 */
	public ICommunity getCommunity() {
		return community;
	}

	/**
	 * @param community the community to set
	 */
	public void setCommunity(ICommunity community) {
		this.community = community;
	}

	/**
	 * @return the building
	 */
	public IBuilding getBuilding() {
		return building;
	}

	/**
	 * @param building the building to set
	 */
	public void setBuilding(IBuilding building) {
		this.building = building;
	}

	/**
	 * @return the heatRoom
	 */
	public IHeatRoom getHeatRoom() {
		return heatRoom;
	}

	/**
	 * @param heatRoom the heatRoom to set
	 */
	public void setHeatRoom(IHeatRoom heatRoom) {
		this.heatRoom = heatRoom;
	}

	/**
	 * @return the concentrator
	 */
	public IConcentrator getConcentrator() {
		return concentrator;
	}

	/**
	 * @param concentrator the concentrator to set
	 */
	public void setConcentrator(IConcentrator concentrator) {
		this.concentrator = concentrator;
	}

	/**
	 * @return the heatSinker
	 */
	public PSinkInfo getHeatSinker() {
		return heatSinker;
	}

	/**
	 * @param heatSinker the heatSinker to set
	 */
	public void setHeatSinker(PSinkInfo heatSinker) {
		this.heatSinker = heatSinker;
	}

	/**
	 * @return the batch2BaseinfoMatch
	 */
	public String getBatch2BaseinfoMatch() {
		return batch2BaseinfoMatch;
	}

	/**
	 * @param batch2BaseinfoMatch the batch2BaseinfoMatch to set
	 */
	public void setBatch2BaseinfoMatch(String batch2BaseinfoMatch) {
		this.batch2BaseinfoMatch = batch2BaseinfoMatch;
	}

	/**
	 * @return the meterDataList
	 */
	public List<IAssignMeterDataGather> getMeterDataList() {
		return meterDataList;
	}

	/**
	 * @param meterDataList the meterDataList to set
	 */
	public void setMeterDataList(List<IAssignMeterDataGather> meterDataList) {
		this.meterDataList = meterDataList;
	}

	/**
	 * @return the dataType
	 */
	public Integer getDataType() {
		return dataType;
	}

	/**
	 * @param dataType the dataType to set
	 */
	public void setDataType(Integer dataType) {
		this.dataType = dataType;
	}

	public Date getReadTime() {
		return readTime;
	}

	public void setReadTime(Date readTime) {
		this.readTime = readTime;
	}

	public ArrayList<QuestionData> getQuestionDatas() {
		return questionDatas;
	}

	public void setQuestionDatas(ArrayList<QuestionData> questionDatas) {
		this.questionDatas = questionDatas;
	}

	public String getNo() {
		return no;
	}

	public void setNo(String no) {
		this.no = no;
	}

	public ArrayList<String> getQuestionDataIDs() {
		return questionDataIDs;
	}

	public void setQuestionDataIDs(ArrayList<String> questionDataIDs) {
		this.questionDataIDs = questionDataIDs;
	}

	public List<AssignDataWithInfo> getDataWithInfos() {
		return dataWithInfos;
	}

	public void setDataWithInfos(List<AssignDataWithInfo> dataWithInfos) {
		this.dataWithInfos = dataWithInfos;
	}

	public List<IAssignMeterDataGather> getSeriousNumList() {
		return seriousNumList;
	}

	public void setSeriousNumList(List<IAssignMeterDataGather> seriousNumList) {
		this.seriousNumList = seriousNumList;
	}
	

	
	
	
	
	
	
	/**
	 * 根据分配表号查询分配表数据
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-10-25
	 */
	public String queryAallotPage() throws Exception {
		//所属项目列表
//		this.seriousNumList = this.iAssignMeterDataGatherService.queryAllSeriousNumInOrderList(seriousNum, recordTime);
//		if (seriousNum == null || "".equals(seriousNum)) {
//			this.seriousNum = this.meterData.getSeriousNum();
//		}
		//分页信息
		this.pageCond = new PageCond();
		int start = (this.pageIndex - 1) * this.pageCond.getLimit();
		this.pageCond.setStart(start);
		//设置查询的抄表日期，遵循就近一致原则
		if(this.startDate==null && this.endDate==null) {
			this.startDate = this.endDate = new Date();
		}
		if(this.startDate!=null && this.endDate==null) {
			this.endDate = this.startDate;
		}
		if(this.startDate==null && this.endDate!=null) {
			this.startDate = this.endDate;
		}
		//分页结果
		if(seriousNum == null || "".equals(seriousNum)){
			this.meterDataPage = null;
		}else {
			this.meterDataPage =iAssignMeterDataGatherService.queryMeterDataAllotPage(
					seriousNum, startDate, endDate, pageCond);
			this.pageSize = new BigDecimal(this.meterDataPage.getPageCond().getTotal())
					.divide(new BigDecimal(this.meterDataPage.getPageCond().getLimit()), RoundingMode.UP)
					.intValue();
			if(pageSize == 0) pageSize = 1;
		}
		//计算结果集的页数
		
		return "allotPage";
	}

	
	
	

	
	
	
	/**
	 * 查询定制查询详细信息(依楼栋分类)
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-12-10
	 */
	public String querySeriousNumAmDataDetail() throws Exception {
		//楼栋数据定制的详细资料
		this.amdCustomizedQuery = iAssignMeterDataGatherService.queryBuildingCustomizedQuery(buildingUID, recordTime);
		//所属楼栋
		if(this.buildingUID!=null && !"".equals(buildingUID)) {
			this.building = iBuildingService.queryEntityById(buildingUID);
		}
		if(building != null) {
			//所属小区
			this.community = iCommunityService.queryEntityById(building.getCommunityID());
			//所属项目
			this.project = iProjectService.queryEntityById(building.getProjectID());
		}
		return "buildingAmDataDetail";
	}
	
	
	
	
	
	
	
}
